﻿using DisconfClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Ymatou.CommonService;
using Ymatou.ServiceCenter;

namespace YmatouSeller.Notice.API
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            UnityConfig.RegisterComponents();

            log4net.Config.XmlConfigurator.Configure();

            try
            {
                ConfigManager.Init(null, typeof(YmatouSeller.Notice.Common.AppSettingHelper).Assembly);
            }
            catch (Exception ex)
            {
                ApplicationLog.Error("通知中心管理后台系统 配置初始化异常：ConfigManager.Init()", ex);
            }
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("json", "true", "application/json"));
            ServiceRegisterManager.InitRpc();
        }

        protected void Application_Error()
        {
            //Tip:统一捕获未处理的异常
            Exception ex = Server.GetLastError();
            ApplicationLog.Error("通知中心管理后台系统 捕获未处理异常：Application_Error()", ex);
            //Server.ClearError();
        }
    }
}